package QianFeng10.EchoDemo;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * 多个客户端
 **/
public class MultipleClientDemo {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        try {
            //创建一个Socket对象，指定要连接的服务器
            Socket socket = new Socket("localhost",6666);
            //获取socket的输入输出流
            PrintStream printStream = new PrintStream(new BufferedOutputStream(socket.getOutputStream()));
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            System.out.println("请输入：");
            String info1 = input.nextLine();
            printStream.println(info1);
            printStream.flush();
            //读取服务器端返回的数据
            String info2 = bufferedReader.readLine();
            System.out.println(info2);
            printStream.close();
            bufferedReader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
